package com.study.spring.ch03.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value="/ch03/params/**") //①处理器的通用映射前缀
public class ReqParamTestController {

	/**
	   *  表示请求中有“create”的参数名且请求方法为“GET”即可匹配
	 * http://×××/ch03/params/abc?create
	 * @return
	 */
	@RequestMapping(params="create", method=RequestMethod.GET)
	public String showForm() {
		System.out.println("================showForm");
		return "ch03/create";
	}
	
	/**
	 * URL“http://×××/parameter1?create
	 * @return
	 */
	@RequestMapping(params="create", method=RequestMethod.POST)
	public String submit() {
		System.out.println("================submit");
		return "redirect:/success";
	}
	
	/**
	   *  请求数据中没有指定参数名的示例
	   *  例子：@RequestMapping(params=“!create”, method=RequestMethod.GET)
	 * http://×××/ch03/params/abc?create
	 * @return
	 */
	@RequestMapping(params="!create", method=RequestMethod.GET)
	public String showForm01() {
		System.out.println("================!create");
		return "ch03/hello";
	}
	
	/**
	   *  请求数据中指定参数名=值的示例
	   *  例子：@RequestMapping(params="submitFlag=create")
	 * http://×××/ch03/params/abc?submitFlag=create
	 * @return
	 */
	@RequestMapping(params="submitFlag=create", method=RequestMethod.GET)
	public String showForm02() {
		System.out.println("================submitFlag=create");
		return "ch03/create";
	}
	
	/**
	   *  请求数据中指定参数名!=值的示例
	   *  例子：@RequestMapping(params="submitFlag!=create")
	 * http://×××/ch03/params/abc?submitFlag=abc
	 * @return
	 */
	@RequestMapping(params="submitFlag!=create", method=RequestMethod.GET)
	public String showForm03() {
		System.out.println("================submitFlag!=create");
		return "ch03/hello";
	}
	
	/**
	   *  组合使用是“且”的关系
	   *  例子：@RequestMapping(params={“test1”, “test2=create”})
	 * http://×××/ch03/params/abc?test1&test2=create
	 * @return
	 */
	@RequestMapping(params={"test1", "test2=create"}, method=RequestMethod.GET)
	public String showForm04() {
		System.out.println("================“test1”, “test2=create”");
		return "ch03/hello";
	}
	
	
}
